Port lint attributes to attribute parser#152369
Port lint attributes to attribute parser#152369Bryntet wants to merge 10 commits intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Port lint attributes to attribute parser
e70b414 to
d9434c9
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
Port lint attributes to attribute parser
|
@rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready cc @jdonszelmann another perf run is queued, because I made a change that hopefully has positive perf compared to the previous (made it so we consolidate all lint attrs into one LintAttributeKind, and then we sort it in |
This comment has been minimized.
This comment has been minimized.
|
apparently running @rustbot author |
also add attr_id to `Stable` variant directly, instead of having to iterate over all the attrs on the hir_id to find it
…tr parser also changes method `parse_limited_all` to take Iterator as an input, to avoid needing to do expensive allocation
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (196eb6d): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -1.2%, secondary 2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.4%, secondary 4.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 482.838s -> 485.094s (0.47%) |
This comment has been minimized.
This comment has been minimized.
also removes E0452 and splits `tests/rustdoc-ui/lints/renamed-lint-still-applies` into 2 tests this is because of delayed warn lint being lost on compiler aborting on error
also buffer any lints coming from pre-expansion, so that they are emitted with proper lint level
| [attr] => { | ||
| if matches!(Level::from_attr(attr), Some((Level::Expect, _))) | ||
| && let metas = attr.meta_item_list() | ||
| && let Some(lst) = metas | ||
| && let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice() | ||
| && let [tool, lint_name] = meta_item.path.segments.as_slice() | ||
| && tool.ident.name == sym::clippy | ||
| && matches!( | ||
| lint_name.ident.name, | ||
| sym::needless_return | sym::style | sym::all | sym::warnings | ||
| ) | ||
| [Attribute::Parsed(AttributeKind::LintAttributes(sub_attrs))] => { | ||
| if !sub_attrs | ||
| .into_iter() | ||
| .filter(|attr| attr.kind == LintAttributeKind::Expect) | ||
| .flat_map(|attr| &attr.lint_instances) | ||
| .any(|lint| { | ||
| matches!( | ||
| lint.original_name_without_tool(), | ||
| sym::needless_return | sym::style | sym::all | sym::warnings | ||
| ) | ||
| }) | ||
| { | ||
| // This is an expectation of the `needless_return` lint | ||
| } else { | ||
| return; | ||
| } | ||
| }, |
There was a problem hiding this comment.
note: this does change behaviour of clippy, I think this behaviour change is a bug fix though.
Basically, previously it was just checking the first meta item, now it actually iterates over all expect attrs
Also we can't use find_attr in clippy for some reason, it emits an FCW (#120192)
| [attr] | ||
| if matches!(Level::from_attr(attr), Some((Level::Expect, _))) | ||
| && let Some(metas) = attr.meta_item_list() | ||
| && let Some(MetaItemInner::MetaItem(meta_item)) = metas.first() | ||
| && let [tool, lint_name] = meta_item.path.segments.as_slice() | ||
| && tool.ident.name == sym::clippy | ||
| && [expected_lint_name, sym::style, sym::all].contains(&lint_name.ident.name) => | ||
| { | ||
| // There is an `expect` attribute -- check that there is no _other_ significant text | ||
| let span_before_attr = inner_if.span.split_at(1).1.until(attr.span()); | ||
| let span_after_attr = attr.span().between(inner_if_expr.span); | ||
| !span_contains_non_whitespace(cx, span_before_attr, self.lint_commented_code) | ||
| && !span_contains_non_whitespace(cx, span_after_attr, self.lint_commented_code) | ||
| [ | ||
| Attribute::Parsed(AttributeKind::LintAttributes(sub_attrs)), | ||
| ] => { | ||
| sub_attrs | ||
| .into_iter() | ||
| .filter(|attr|attr.kind == LintAttributeKind::Expect) | ||
| .flat_map(|attr| attr.lint_instances.iter().map(|group| (attr.attr_span, group))) | ||
| .filter(|(_, lint_id)| { | ||
| lint_id.tool_is_named(sym::clippy) | ||
| && (expected_lint_name == lint_id.lint_name() | ||
| || [expected_lint_name, sym::style, sym::all] | ||
| .contains(&lint_id.original_name_without_tool())) | ||
| }) | ||
| .any(|(attr_span, _)| { | ||
| // There is an `expect` attribute -- check that there is no _other_ significant text | ||
| let span_before_attr = inner_if.span.split_at(1).1.until(attr_span); | ||
| let span_after_attr = attr_span.between(inner_if_expr.span); | ||
| !span_contains_non_whitespace(cx, span_before_attr, self.lint_commented_code) | ||
| && !span_contains_non_whitespace(cx, span_after_attr, self.lint_commented_code) | ||
| }) |
|
@rustbot ready |
View all comments
Tracking issue: #131229
Ports
#[allow],#[deny],#[expect],#[forbid], and#[warn]to being parsed attrsI tried my best to make this PR as small as possible, it was difficult. I hope it isn't too difficult to review
r? @JonathanBrouwer
r? @jdonszelmann